package design_pattern.momento.Test2;

/**
 * Created by WeiDingKuo on 2017/10/27 14:59
 * <p>
 * 备忘录模式--黑盒模式
 * <p>
 * 与白盒模式的区别在于，Momento 为 Orignator的匿名内部类，实现MomentoIF接口
 * 这样Momento对象的细节对Orignator对象完全公开，对外部CareTaker对象完全封闭
 */
public class Test {
    public static void main(String[] args) {
        Orignator orignator = new Orignator();
        CareTaker careTaker = new CareTaker();

        orignator.setName("zhangsan");
        System.out.println(orignator.getName());
        careTaker.saveMomento(orignator.createMomento());

        orignator.setName("lisi");
        System.out.println(orignator.getName());
        orignator.restoreMomento(careTaker.retrieveMomento());
        System.out.println(orignator.getName());
    }
}
